package com.Iconcat.system.controller;


import com.Iconcat.system.entity.DrawRecord;
import com.Iconcat.system.entity.MovieBoxOffice;
import com.Iconcat.system.response.Result;
import com.Iconcat.system.service.DrawRecordService;
import com.Iconcat.system.vo.DrawRecordto;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zzq
 * @since 2023-11-13
 */
@RestController
@RequestMapping("/DrawRecord")
@CrossOrigin
@Api(value = "抽奖",tags = "抽奖接口")
public class DrawRecordController {
    @Resource
    private DrawRecordService drawRecordService;
    @PostMapping("/start")
    public Result drawPrize(@RequestBody DrawRecordto drawRecordto ) {
       Integer userId=drawRecordto.getUserId();
       String prizeName=drawRecordto.getPrizeName();
       Integer drawType=drawRecordto.getDrawType();
        // 假设前端已经进行了随机抽奖计算，将结果传递给后端
        Result result = drawRecordService.drawPrize(userId, prizeName, drawType);
        return result;
    }
    @GetMapping("/recordList")
    public Result recordList(@RequestParam(required = true, defaultValue = "1") Integer current,
                             @RequestParam(required = true, defaultValue = "6") Integer size,
                              @RequestParam(required = true) Integer userId) {
       Result result=drawRecordService.recordList(userId,current,size);
    return result;
    }
    @GetMapping("/list")
    public Result recordBigList(@RequestParam(required = true, defaultValue = "1") Integer current,
                             @RequestParam(required = true, defaultValue = "6") Integer size,
                             @RequestParam(required = false) Integer searchKeyword) {
        Page<DrawRecord> page = new Page<>(current, size);
        IPage<Map<String, Object>> result = drawRecordService.getDrawRecordListPage(page);
        return Result.ok().data("list", result);
    }
}

